import sys,apachelogs
from qqip import get_location

alf = iter(apachelogs.ApacheLogFile(sys.argv[1]))

first_line = alf.next()

ip = first_line.ip
count = 1
time = first_line.time
download = first_line.http_response_size

for line in alf:
    if ip == line.ip:
        count += 1
        download += line.http_response_size
    else:
        print time, ip, get_location(ip), '%iKB'%(download/1024) 
        
        ip = line.ip
        count = 1
        time = line.time
        download = line.http_response_size
